package com.example.voting_master.controller;

import cn.hutool.core.util.StrUtil;
import com.example.voting_master.common.api.Result;
import com.example.voting_master.entity.UserVoteLog;
import com.example.voting_master.service.UserVoteLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserVoteLogController {

    @Autowired
    private UserVoteLogService userVoteLogService;

    @PostMapping("/vote")
    public Result<Boolean> vote(HttpServletRequest request, @RequestBody UserVoteLog userVoteLog) {
        String result = userVoteLogService.user_vote(request,userVoteLog);
        if(StrUtil.isBlank(result)) {
            return Result.success(true,"投票成功");
        }else
            return Result.error(result);
    }
}
